package com.yanq.liancar.adapter;
/*
 *  @创建者     Administrator
 *  @创建时间   2018/10/10  15:03
 *  @描述       ${TODO}
 */


import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.vondear.rxtool.RxActivityTool;
import com.yanq.liancar.R;
import com.yanq.liancar.activity.SmallBEJGoodsListActivity;
import com.yanq.liancar.bean.FindCommentTwoBean;

import java.util.List;

public class SmallFindCommentAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    private List<FindCommentTwoBean.DataBean.CommentsRepliesBean> mList;
    private int id;
    private final int EMPTY_VIEW = 1;
    //private OnItemClickListener clickListener;
    private final int PROGRESS_VIEW = 2;

    public SmallFindCommentAdapter(Context context, List<FindCommentTwoBean.DataBean.CommentsRepliesBean> mList, int Bid) {
        this.mContext = context;
        this.mList = mList;
        this.id = Bid;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view;
        if (viewType == EMPTY_VIEW) {
            view = LayoutInflater.from(mContext).inflate(R.layout.smallfindcomment1, parent, false);
            return new MyViewHolder1(view);
        } else {
            view = LayoutInflater.from(mContext).inflate(R.layout.smallfindcomment2, parent, false);
            return new MyViewHolder2(view);
        }
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        });
        if (mList!=null){
            if (holder instanceof MyViewHolder1){
                MyViewHolder1 holder1= (MyViewHolder1) holder;
                holder1.name.setText(mList.get(position).getRepliername()+":");
                holder1.content1.setText(mList.get(position).getReplycontent());
            }else if (holder instanceof MyViewHolder2){
                MyViewHolder2 holder2= (MyViewHolder2) holder;
                holder2.name1.setText(mList.get(position).getRepliername());
                holder2.name2.setText(mList.get(position).getObjectname()+":");
                holder2.content2.setText(mList.get(position).getReplycontent());
            }
        }

    }

//        @Override
//        public void onBindViewHolder(@NonNull MyViewHolder holder, final int position) {
//            if (mList!=null){
//                holder.mTextView.setText(mList.get(position).getSmall_classifyname());
//                holder.itemView.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View view) {
//                        Bundle bundle = new Bundle();
//                        bundle.putString("where", "SmallSelectClassAdapter");
//                        bundle.putInt("Bid", id);
//                        bundle.putInt("Sid", mList.get(position).getSmallclassifyid());
//                        RxActivityTool.skipActivity(mContext, SmallBEJGoodsListActivity.class, bundle);
//                    }
//                });
//            }
//        }

    @Override
    public int getItemCount() {
        return (mList == null ? 0 : mList.size());
    }

    @Override
    public int getItemViewType(int position) {
        if (mList.get(position).getReplytype() == 1) {
            return EMPTY_VIEW;
        } else if (mList.get(position).getReplytype() == 2) {
            return PROGRESS_VIEW;
        } else {
            return super.getItemViewType(position);
        }
    }

    class MyViewHolder1 extends RecyclerView.ViewHolder {
        TextView name;
        TextView content1;

        public MyViewHolder1(View itemView) {
            super(itemView);
            name = itemView.findViewById(R.id.tv_name);
            content1 = itemView.findViewById(R.id.tv_content);
        }
    }

    class MyViewHolder2 extends RecyclerView.ViewHolder {
        TextView name1;
        TextView name2;
        TextView content2;

        public MyViewHolder2(View itemView) {
            super(itemView);
            name1 = itemView.findViewById(R.id.tv_name1);
            name2 = itemView.findViewById(R.id.tv_name2);
            content2 = itemView.findViewById(R.id.tv_content);
        }
    }
}
